import request from '@/config/axios'
import type { PageParam } from '@/types/global'

export interface CommentVO {
  id: number
  userId: number
  userNickname: string
  userAvatar: string
  anonymous: boolean
  orderId: number
  orderItemId: number
  spuId: number
  spuName: string
  skuId: number
  visible: boolean
  scores: number
  descriptionScores: number
  benefitScores: number
  content: string
  picUrls: string
  replyStatus: boolean
  replyUserId: number
  replyContent: string
  replyTime: Date
}

// 查询商品评价分页
export const getCommentPage = (params: PageParam) => {
  const finalParams = { ...params, productType: 'SHOP' };
  return request.get({
    url: '/product/comment/page',
    params: finalParams
  })
}

// 查询商品评论详情
export const getComment = (id: number) => {
  const url = `/product/comment/get?id=${id}&productType=SHOP`;
  return request.get({ url })
}

// 添加自评
export const createComment = async (data: CommentVO) => {
  return await request.post({ url: `/product/comment/create`, data })
}

// 显示 / 隐藏评论
export const updateCommentVisible = (data: CommentVO) => {
  const finalData = { ...data, productType: 'SHOP' };
  return request.put({
    url: '/product/comment/update-visible',
    data: finalData
  })
}

// 商家回复商品评价
export const replyComment = (data: CommentVO) => {
  const finalData = { ...data, productType: 'SHOP' };
  return request.put({
    url: '/product/comment/reply',
    data: finalData
  })
}
